<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>战力值预估工具</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            line-height: 1.6;
        }
        .container {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
        }
        .panel {
            flex: 1;
            min-width: 300px;
            border: 1px solid #ddd;
            padding: 15px;
            border-radius: 5px;
            background-color: #f9f9f9;
        }
        h2 {
            color: #333;
            border-bottom: 1px solid #eee;
            padding-bottom: 10px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
            font-size: 14px;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
            position: sticky;
            top: 0;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input, select {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            margin-right: 10px;
        }
        button:hover {
            background-color: #45a049;
        }
        .result {
            font-weight: bold;
            color: #2c3e50;
            margin-top: 10px;
            padding: 10px;
            background-color: #e8f5e9;
            border-radius: 4px;
        }
        .opportunity-form {
            margin-bottom: 15px;
            padding: 10px;
            background-color: #fff;
            border-radius: 4px;
            border: 1px solid #e0e0e0;
        }
        .remove-btn {
            background-color: #f44336;
            padding: 5px 10px;
            font-size: 12px;
        }
        .remove-btn:hover {
            background-color: #d32f2f;
        }
        .scrollable-table {
            max-height: 400px;
            overflow-y: auto;
            display: block;
        }
        .highlight {
            background-color: #fffde7;
        }
    </style>
</head>
<body>
    <h1>战力值预估工具</h1>
    
    <div class="container">
        <div class="panel">
            <h2>全国统计数据</h2>
            <table>
                <tr>
                    <th>条件</th>
                    <th>人数</th>
                    <th>战力值范围</th>
                </tr>
                <tr>
                    <td>全国客户代表人数</td>
                    <td id="totalReps">117</td>
                    <td>0-3481</td>
                </tr>
                <tr>
                    <td>战力值前20%</td>
                    <td id="top20">23</td>
                    <td>>759</td>
                </tr>
                <tr>
                    <td>战力值后20%</td>
                    <td id="bottom20">23</td>
                    <td>&lt;138</td>
                </tr>
            </table>
            
            <h2>客户代表列表</h2>
            <div class="scrollable-table">
                <table id="repList">
                    <thead>
                        <tr>
                            <th>排名</th>
                            <th>客户代表</th>
                            <th>战力值</th>
                            <th>排名率</th>
                            <th>战区代表处</th>
                        </tr>
                    </thead>
                    <tbody>
                        <!-- 数据将通过JavaScript动态加载 -->
                    </tbody>
                </table>
            </div>
        </div>
        
        <div class="panel">
            <h2>战力值预估</h2>
            <div class="form-group">
                <label for="repSelect">选择客户代表:</label>
                <select id="repSelect">
                    <option value="">-- 请选择 --</option>
                    <!-- 选项将通过JavaScript动态加载 -->
                </select>
            </div>
            
            <div id="currentInfo" style="display:none;">
                <div class="result">
                    <p><strong>当前战力值:</strong> <span id="currentPower">0</span> 万元</p>
                    <p><strong>当前排名率:</strong> <span id="currentRank">0%</span></p>
                    <p><strong>战区代表处:</strong> <span id="currentRegion"></span></p>
                    <p><strong>所属PA小组:</strong> <span id="currentGroup"></span></p>
                </div>
            </div>
            
            <h3>新增商机</h3>
            <div id="opportunities">
                <!-- 商机表单将通过JavaScript动态添加 -->
            </div>
            <button type="button" onclick="addOpportunity()">添加商机</button>
            
            <div class="form-group">
                <label for="estimatedSignings">预估签约个数:</label>
                <input type="number" id="estimatedSignings" min="0" step="1">
            </div>
            
            <div class="form-group">
                <label for="estimatedAmount">预估签约总金额(万元):</label>
                <input type="number" id="estimatedAmount" min="0" step="0.01">
            </div>
            
            <button type="button" onclick="calculate()">计算预估战力值</button>
            <button type="button" onclick="resetForm()" style="background-color: #607d8b;">重置</button>
            
            <div id="result" class="result" style="display:none;">
                <h3>预估结果</h3>
                <p><strong>签约战力值:</strong> <span id="signingPower">0</span> 万元</p>
                <p><strong>预估战力值:</strong> <span id="estimatedPower">0</span> 万元</p>
                <p><strong>预估排名率:</strong> <span id="estimatedRank">0%</span></p>
                <p><strong>排名变化:</strong> <span id="rankChange">-</span></p>
            </div>
        </div>
    </div>

    <script>
        // 从Excel中提取的数据
        const repData = [
            { rank: 1, name: "谢陈琴", power: 3480.58, rankRate: "0.85%", region: "上海战区代表处", group: "宁波客户代表二组" },
            { rank: 2, name: "徐存", power: 2263.43, rankRate: "1.71%", region: "上海战区代表处", group: "绍兴客户代表一组" },
            { rank: 3, name: "刘建军", power: 2109.04, rankRate: "2.56%", region: "湘赣战区代表处", group: "长沙客户代表二组" },
            { rank: 4, name: "包思佳", power: 2051.58, rankRate: "3.42%", region: "上海战区代表处", group: "南通客户代表三组" },
            { rank: 5, name: "张怡", power: 1985.67, rankRate: "4.27%", region: "上海战区代表处", group: "上海客户代表二组" },
            { rank: 6, name: "汪竹婷", power: 1699.61, rankRate: "5.13%", region: "上海战区代表处", group: "宁波客户代表五组" },
            { rank: 7, name: "唐浩帆", power: 1503.95, rankRate: "5.98%", region: "湘赣战区代表处", group: "长沙客户代表三组" },
            { rank: 8, name: "底娜", power: 1303.18, rankRate: "6.84%", region: "津晋战区代表处", group: "天津政府客户代表组" },
            { rank: 9, name: "马帅", power: 1233.18, rankRate: "7.69%", region: "山东战区代表处", group: "济南客户代表二组" },
            { rank: 10, name: "杨雪琳", power: 1206.93, rankRate: "8.55%", region: "广州战区代表处", group: "东莞客户代表二组" },
            { rank: 11, name: "曹靖妮", power: 1124.94, rankRate: "9.40%", region: "深圳战区代表处", group: "深圳客户代表五组" },
            { rank: 12, name: "何淑贤", power: 1114.65, rankRate: "10.26%", region: "广州战区代表处", group: "广州客户代表三组" },
            { rank: 13, name: "陈旭东", power: 1087.20, rankRate: "11.11%", region: "津晋战区代表处", group: "太原政府客户代表组" },
            { rank: 14, name: "谢瑞", power: 1029.57, rankRate: "11.97%", region: "安徽战区代表处", group: "合六客户代表组" },
            { rank: 15, name: "黄杰", power: 976.50, rankRate: "12.82%", region: "京冀战区代表处", group: "北京客户代表三组" },
            { rank: 16, name: "张正卫", power: 962.98, rankRate: "13.68%", region: "苏州战区代表处", group: "无锡客户代表一组" },
            { rank: 17, name: "牛学康", power: 909.84, rankRate: "14.53%", region: "京冀战区代表处", group: "北京客户代表二组" },
            { rank: 18, name: "杨世全", power: 888.06, rankRate: "15.38%", region: "渝贵战区代表处", group: "重庆客户代表五组" },
            { rank: 19, name: "赵庭婷", power: 863.15, rankRate: "16.24%", region: "渝贵战区代表处", group: "重庆客户代表一组" },
            { rank: 20, name: "陈娟", power: 848.13, rankRate: "17.09%", region: "湘赣战区代表处", group: "南昌客户代表一组" },
            { rank: 21, name: "王文彬", power: 839.07, rankRate: "17.95%", region: "川云战区代表处", group: "成都客户代表二组" },
            { rank: 22, name: "许蓉蓉", power: 772.91, rankRate: "18.80%", region: "安徽战区代表处", group: "芜马客户代表组" },
            { rank: 23, name: "杨鹏飞", power: 759.22, rankRate: "19.66%", region: "厦门战区代表处", group: "泉州大企业客户代表组" },
            { rank: 24, name: "姚豪", power: 753.05, rankRate: "20.51%", region: "鄂豫战区代表处", group: "武汉客户代表三组" },
            { rank: 25, name: "王旌源", power: 715.00, rankRate: "21.37%", region: "苏州战区代表处", group: "常州客户代表一组" },
            { rank: 26, name: "冯岩岩", power: 683.95, rankRate: "22.22%", region: "京冀战区代表处", group: "北京客户代表四组" },
            { rank: 27, name: "李永健", power: 674.36, rankRate: "23.08%", region: "京冀战区代表处", group: "廊坊客户代表一组" },
            { rank: 28, name: "施洪林", power: 656.33, rankRate: "23.93%", region: "广州战区代表处", group: "东莞客户代表四组" },
            { rank: 29, name: "黄健", power: 642.53, rankRate: "24.79%", region: "苏州战区代表处", group: "苏州客户代表二组" },
            { rank: 30, name: "唐启翔", power: 640.36, rankRate: "25.64%", region: "鄂豫战区代表处", group: "武汉客户代表一组" },
            { rank: 31, name: "康恺", power: 640.32, rankRate: "26.50%", region: "津晋战区代表处", group: "太原大企业客户代表组" },
            { rank: 32, name: "冯威", power: 637.35, rankRate: "27.35%", region: "西北战区代表处", group: "西安客户代表三组" },
            { rank: 33, name: "李楠菊", power: 614.35, rankRate: "28.21%", region: "渝贵战区代表处", group: "贵阳客户代表一组" },
            { rank: 34, name: "徐贤", power: 585.09, rankRate: "29.06%", region: "苏州战区代表处", group: "苏州客户代表一组" },
            { rank: 35, name: "吴嘉", power: 580.77, rankRate: "29.91%", region: "琼桂战区代表处", group: "南宁客户代表二组" },
            { rank: 36, name: "辛海燕", power: 567.80, rankRate: "30.77%", region: "山东战区代表处", group: "青岛客户代表一组" },
            { rank: 37, name: "林方云", power: 562.20, rankRate: "31.62%", region: "苏州战区代表处", group: "无锡客户代表二组" },
            { rank: 38, name: "冯野", power: 544.39, rankRate: "32.48%", region: "深圳战区代表处", group: "惠州客户代表一组" },
            { rank: 39, name: "张瑾", power: 539.74, rankRate: "33.33%", region: "福州战区代表处", group: "福州客户代表四组" },
            { rank: 40, name: "周琳", power: 534.15, rankRate: "34.19%", region: "鄂豫战区代表处", group: "洛阳客户代表组" },
            { rank: 41, name: "刘佳伟", power: 523.54, rankRate: "35.04%", region: "上海战区代表处", group: "南通客户代表一组" },
            { rank: 42, name: "何海彬", power: 521.71, rankRate: "35.90%", region: "湘赣战区代表处", group: "南昌客户代表三组" },
            { rank: 43, name: "谭小凡", power: 519.55, rankRate: "36.75%", region: "湘赣战区代表处", group: "长沙客户代表一组" },
            { rank: 44, name: "魏华", power: 501.86, rankRate: "37.61%", region: "深圳战区代表处", group: "深圳客户代表二组" },
            { rank: 45, name: "马有锐", power: 487.04, rankRate: "38.46%", region: "京冀战区代表处", group: "北京客户代表一组" },
            { rank: 46, name: "李晓静", power: 482.28, rankRate: "39.32%", region: "深圳战区代表处", group: "深圳客户代表四组" },
            { rank: 47, name: "吕爱萍", power: 478.10, rankRate: "40.17%", region: "川云战区代表处", group: "昆明客户代表一组" },
            { rank: 48, name: "雷鸣", power: 476.68, rankRate: "41.03%", region: "上海战区代表处", group: "南通客户代表二组" },
            { rank: 49, name: "华涛", power: 456.54, rankRate: "41.88%", region: "山东战区代表处", group: "青岛客户代表四组" },
            { rank: 50, name: "姚俊", power: 449.76, rankRate: "42.74%", region: "苏州战区代表处", group: "泰州客户代表一组" },
            { rank: 51, name: "石晨", power: 447.92, rankRate: "43.59%", region: "东北战区代表处", group: "抚顺客户代表组" },
            { rank: 52, name: "刘兆艳", power: 445.80, rankRate: "44.44%", region: "苏州战区代表处", group: "苏州客户代表三组" },
            { rank: 53, name: "王伟成", power: 401.68, rankRate: "45.30%", region: "琼桂战区代表处", group: "海南客户代表二组" },
            { rank: 54, name: "史皓文", power: 400.58, rankRate: "46.15%", region: "上海战区代表处", group: "宁波客户代表三组" },
            { rank: 55, name: "詹邵飞", power: 374.39, rankRate: "47.01%", region: "厦门战区代表处", group: "漳州政府客户代表组" },
            { rank: 56, name: "王超", power: 362.83, rankRate: "47.86%", region: "山东战区代表处", group: "烟台客户代表一组" },
            { rank: 57, name: "王华平", power: 362.11, rankRate: "48.72%", region: "湘赣战区代表处", group: "南昌客户代表二组" },
            { rank: 58, name: "杨超超", power: 360.01, rankRate: "49.57%", region: "川云战区代表处", group: "成都客户代表三组" },
            { rank: 59, name: "叶飞", power: 357.98, rankRate: "50.43%", region: "佛山战区代表处", group: "珠海客户代表一组" },
            { rank: 60, name: "龙平", power: 355.74, rankRate: "51.28%", region: "广州战区代表处", group: "东莞客户代表一组" },
            { rank: 61, name: "骆涛", power: 351.85, rankRate: "52.14%", region: "安徽战区代表处", group: "合肥客户代表组" },
            { rank: 62, name: "杨彦", power: 337.00, rankRate: "52.99%", region: "川云战区代表处", group: "成都客户代表一组" },
            { rank: 63, name: "赵景璐", power: 328.16, rankRate: "53.85%", region: "山东战区代表处", group: "青岛客户代表三组" },
            { rank: 64, name: "严宇", power: 320.84, rankRate: "54.70%", region: "鄂豫战区代表处", group: "武汉客户代表二组" },
            { rank: 65, name: "王文彬", power: 317.13, rankRate: "55.56%", region: "川云战区代表处", group: "宜宾客户代表一组" },
            { rank: 66, name: "麻金福", power: 311.01, rankRate: "56.41%", region: "京冀战区代表处", group: "北京客户代表五组" },
            { rank: 67, name: "刘晶珂", power: 310.78, rankRate: "57.26%", region: "琼桂战区代表处", group: "南宁客户代表一组" },
            { rank: 68, name: "程龙", power: 301.79, rankRate: "58.12%", region: "深圳战区代表处", group: "深圳客户代表三组" },
            { rank: 69, name: "高楣", power: 298.64, rankRate: "58.97%", region: "福州战区代表处", group: "福州客户代表一组" },
            { rank: 70, name: "方苹", power: 291.71, rankRate: "59.83%", region: "深圳战区代表处", group: "深圳客户代表一组" },
            { rank: 71, name: "皇浩亮", power: 287.95, rankRate: "60.68%", region: "鄂豫战区代表处", group: "郑州客户代表一组" },
            { rank: 72, name: "李林", power: 286.62, rankRate: "61.54%", region: "西北战区代表处", group: "西安客户代表四组" },
            { rank: 73, name: "陈丹", power: 285.52, rankRate: "62.39%", region: "福州战区代表处", group: "福州客户代表三组" },
            { rank: 74, name: "赵勇", power: 276.43, rankRate: "63.25%", region: "杭州战区代表处", group: "温州客户代表一组" },
            { rank: 75, name: "蔡兴华", power: 271.35, rankRate: "64.10%", region: "上海战区代表处", group: "上海客户代表一组" },
            { rank: 76, name: "付豪", power: 257.10, rankRate: "64.96%", region: "琼桂战区代表处", group: "海南客户代表一组" },
            { rank: 77, name: "弋乐", power: 254.54, rankRate: "65.81%", region: "西北战区代表处", group: "西安客户代表一组" },
            { rank: 78, name: "顾雪存", power: 244.00, rankRate: "66.67%", region: "广州战区代表处", group: "广州客户代表一组" },
            { rank: 79, name: "吕健昂", power: 242.01, rankRate: "67.52%", region: "杭州战区代表处", group: "杭州客户代表一组" },
            { rank: 80, name: "许杨", power: 240.32, rankRate: "68.38%", region: "杭州战区代表处", group: "金台客户代表组" },
            { rank: 81, name: "江玮", power: 236.40, rankRate: "69.23%", region: "福州战区代表处", group: "宁德客户代表组" },
            { rank: 82, name: "陈吉腾", power: 226.38, rankRate: "70.09%", region: "厦门战区代表处", group: "漳州大企业客户代表组" },
            { rank: 83, name: "吴昊雅", power: 215.32, rankRate: "70.94%", region: "渝贵战区代表处", group: "贵阳客户代表二组" },
            { rank: 84, name: "罗玉生", power: 204.37, rankRate: "71.79%", region: "厦门战区代表处", group: "厦门政府客户代表组" },
            { rank: 85, name: "沈维娜", power: 197.38, rankRate: "72.65%", region: "安徽战区代表处", group: "合蚌客户代表组" },
            { rank: 86, name: "王胜彬", power: 192.95, rankRate: "73.50%", region: "鄂豫战区代表处", group: "郑州客户代表二组" },
            { rank: 87, name: "李波", power: 190.56, rankRate: "74.36%", region: "津晋战区代表处", group: "天津开发商客户代表组" },
            { rank: 88, name: "马宁", power: 190.38, rankRate: "75.21%", region: "津晋战区代表处", group: "天津大企业客户代表组" },
            { rank: 89, name: "闫荣", power: 189.93, rankRate: "76.07%", region: "西北战区代表处", group: "银川客户代表一组" },
            { rank: 90, name: "杨涛", power: 169.88, rankRate: "76.92%", region: "苏州战区代表处", group: "常州客户代表二组" },
            { rank: 91, name: "王恩伟", power: 148.83, rankRate: "77.78%", region: "东北战区代表处", group: "哈尔滨客户代表一组" },
            { rank: 92, name: "覃巧术", power: 146.74, rankRate: "78.63%", region: "佛山战区代表处", group: "中山客户代表一组" },
            { rank: 93, name: "李云飞", power: 137.97, rankRate: "79.49%", region: "南京战区代表处", group: "徐州客户代表组" },
            { rank: 94, name: "贾阳欣", power: 133.70, rankRate: "80.34%", region: "上海战区代表处", group: "嘉兴客户代表二组" },
            { rank: 95, name: "陈茜茜", power: 128.16, rankRate: "81.20%", region: "福州战区代表处", group: "福州客户代表二组" },
            { rank: 96, name: "郭汉隆", power: 122.27, rankRate: "82.05%", region: "厦门战区代表处", group: "厦门大企业客户代表组" },
            { rank: 97, name: "李晓锋", power: 120.59, rankRate: "82.91%", region: "西北战区代表处", group: "兰州客户代表一组" },
            { rank: 98, name: "严玉涛", power: 111.90, rankRate: "83.76%", region: "东北战区代表处", group: "大连开发商客户代表组" },
            { rank: 99, name: "庄雨霖", power: 109.36, rankRate: "84.62%", region: "南京战区代表处", group: "南京客户代表二组" },
            { rank: 100, name: "贾人歌", power: 102.90, rankRate: "85.47%", region: "山东战区代表处", group: "烟台客户代表二组" },
            { rank: 101, name: "黄世超", power: 102.00, rankRate: "86.32%", region: "广州战区代表处", group: "广州客户代表四组" },
            { rank: 102, name: "蔡虎", power: 98.35, rankRate: "87.18%", region: "西北战区代表处", group: "西安客户代表二组" },
            { rank: 103, name: "陈晓", power: 95.99, rankRate: "88.03%", region: "福州战区代表处", group: "莆田客户代表组" },
            { rank: 104, name: "郑谢婷", power: 72.54, rankRate: "88.89%", region: "上海战区代表处", group: "宁波客户代表一组" },
            { rank: 105, name: "黄瑞武", power: 67.34, rankRate: "89.74%", region: "佛山战区代表处", group: "珠海客户代表二组" },
            { rank: 106, name: "钱慧", power: 50.81, rankRate: "90.60%", region: "南京战区代表处", group: "南京客户代表一组" },
            { rank: 107, name: "何伟", power: 45.32, rankRate: "91.45%", region: "东北战区代表处", group: "长春客户代表一组" },
            { rank: 108, name: "陈广峰", power: 42.13, rankRate: "92.31%", region: "山东战区代表处", group: "济南客户代表三组" },
            { rank: 109, name: "赵凯", power: 31.59, rankRate: "93.16%", region: "山东战区代表处", group: "济南客户代表一组" },
            { rank: 110, name: "周宁", power: 27.30, rankRate: "94.02%", region: "厦门战区代表处", group: "泉州开发商客户代表组" },
            { rank: 111, name: "吴立卿", power: 10.85, rankRate: "94.87%", region: "杭州战区代表处", group: "杭州客户代表三组" },
            { rank: 112, name: "潘鋆", power: 5.10, rankRate: "95.73%", region: "湘赣战区代表处", group: "长沙客户代表四组" },
            { rank: 113, name: "封佳飞", power: 0.00, rankRate: "96.58%", region: "上海战区代表处", group: "上海客户代表三组" },
            { rank: 114, name: "于冰洋", power: 0.00, rankRate: "97.44%", region: "上海战区代表处", group: "宁波客户代表四组" },
            { rank: 115, name: "张萌", power: 0.00, rankRate: "98.29%", region: "东北战区代表处", group: "大连大企业客户代表组" },
            { rank: 116, name: "李毅", power: 0.00, rankRate: "99.15%", region: "川云战区代表处", group: "昆明客户代表二组" },
            { rank: 117, name: "余鹏", power: 0.00, rankRate: "100.00%", region: "苏州战区代表处", group: "无锡客户代表三组" }
        ];

        const opportunityTypes = [
            "万科物业", "万物梁行", "万睿科技", "丹田", 
            "万物云城", "祥盈企服", "修缮"
        ];

        const opportunityValues = {
            "万科物业": { avgContract: 453, clue: 20.385, opportunity: 33.975, bidding: 67.95 },
            "万物梁行": { avgContract: 455, clue: 20.475, opportunity: 34.125, bidding: 68.25 },
            "万睿科技": { avgContract: 241, clue: 10.845, opportunity: 18.075, bidding: 36.15 },
            "丹田": { avgContract: 265, clue: 11.925, opportunity: 19.875, bidding: 39.75 },
            "万物云城": { avgContract: 150, clue: 6.75, opportunity: 11.25, bidding: 22.5 },
            "祥盈企服": { avgContract: 249, clue: 11.205, opportunity: 18.675, bidding: 37.35 },
            "修缮": { avgContract: 36, clue: 1.62, opportunity: 2.7, bidding: 5.4 }
        };

        // 初始化页面
        document.addEventListener('DOMContentLoaded', function() {
            // 填充客户代表列表
            const repList = document.getElementById('repList').getElementsByTagName('tbody')[0];
            const repSelect = document.getElementById('repSelect');
            
            repData.forEach(rep => {
                // 添加到表格
                const row = repList.insertRow();
                row.insertCell(0).textContent = rep.rank;
                row.insertCell(1).textContent = rep.name;
                row.insertCell(2).textContent = rep.power.toFixed(2);
                row.insertCell(3).textContent = rep.rankRate;
                row.insertCell(4).textContent = rep.region;
                
                // 添加到下拉框
                const option = document.createElement('option');
                option.value = rep.name;
                option.textContent = `${rep.name} (${rep.region})`;
                option.dataset.region = rep.region;
                option.dataset.group = rep.group;
                repSelect.appendChild(option);
            });
            
            // 添加一个默认商机表单
            addOpportunity();
        });

        // 客户代表选择变化时
        document.getElementById('repSelect').addEventListener('change', function() {
            const selectedRep = this.value;
            const currentInfo = document.getElementById('currentInfo');
            
            if (selectedRep) {
                const selectedOption = this.options[this.selectedIndex];
                const rep = repData.find(r => r.name === selectedRep);
                
                document.getElementById('currentPower').textContent = rep.power.toFixed(2);
                document.getElementById('currentRank').textContent = rep.rankRate;
                document.getElementById('currentRegion').textContent = rep.region;
                document.getElementById('currentGroup').textContent = rep.group;
                
                currentInfo.style.display = 'block';
                
                // 高亮显示选中的客户代表
                const rows = document.querySelectorAll('#repList tbody tr');
                rows.forEach(row => {
                    if (row.cells[1].textContent === selectedRep) {
                        row.classList.add('highlight');
                    } else {
                        row.classList.remove('highlight');
                    }
                });
            } else {
                currentInfo.style.display = 'none';
                
                // 移除所有高亮
                const rows = document.querySelectorAll('#repList tbody tr');
                rows.forEach(row => row.classList.remove('highlight'));
            }
        });

        // 添加商机表单
        function addOpportunity() {
            const container = document.getElementById('opportunities');
            const div = document.createElement('div');
            div.className = 'opportunity-form';
            div.innerHTML = `
                <div class="form-group">
                    <label>商机类型:</label>
                    <select class="opp-type">
                        ${opportunityTypes.map(type => `<option value="${type}">${type}</option>`).join('')}
                    </select>
                </div>
                <div class="form-group">
                    <label>线索数量:</label>
                    <input type="number" class="clue" min="0" step="1" placeholder="数量">
                </div>
                <div class="form-group">
                    <label>商机数量:</label>
                    <input type="number" class="opp" min="0" step="1" placeholder="数量">
                </div>
                <div class="form-group">
                    <label>招投标数量:</label>
                    <input type="number" class="bidding" min="0" step="1" placeholder="数量">
                </div>
                <button type="button" class="remove-btn" onclick="this.parentNode.remove()">删除</button>
            `;
            container.appendChild(div);
        }

        // 计算预估战力值
        function calculate() {
            const repSelect = document.getElementById('repSelect');
            const selectedRep = repSelect.value;
            
            if (!selectedRep) {
                alert('请先选择客户代表');
                return;
            }
            
            const rep = repData.find(r => r.name === selectedRep);
            let estimatedPower = parseFloat(rep.power);
            
            // 计算商机贡献的战力值
            const opportunityForms = document.querySelectorAll('.opportunity-form');
            opportunityForms.forEach(form => {
                const type = form.querySelector('.opp-type').value;
                const clueCount = parseInt(form.querySelector('.clue').value) || 0;
                const oppCount = parseInt(form.querySelector('.opp').value) || 0;
                const biddingCount = parseInt(form.querySelector('.bidding').value) || 0;
                
                const values = opportunityValues[type];
                estimatedPower += clueCount * values.clue;
                estimatedPower += oppCount * values.opportunity;
                estimatedPower += biddingCount * values.bidding;
            });
            
            // 计算签约贡献的战力值
            const signings = parseInt(document.getElementById('estimatedSignings').value) || 0;
            const amount = parseFloat(document.getElementById('estimatedAmount').value) || 0;
            const signingPower = amount * 0.7 - signings * (estimatedPower - rep.power) * 0.3;
            
            estimatedPower += signingPower;
            
            // 计算预估排名率
            const higherReps = repData.filter(r => r.power > estimatedPower).length;
            const rankPercentage = (higherReps / repData.length * 100).toFixed(2);
            const newRank = higherReps + 1;
            const rankChange = rep.rank - newRank;
            
            // 显示结果
            document.getElementById('signingPower').textContent = signingPower.toFixed(2);
            document.getElementById('estimatedPower').textContent = estimatedPower.toFixed(2);
            document.getElementById('estimatedRank').textContent = rankPercentage + '%';
            
            let rankChangeText = `从 ${rep.rank} 名变为 ${newRank} 名`;
            if (rankChange > 0) {
                rankChangeText += ` (上升 ${rankChange} 名)`;
            } else if (rankChange < 0) {
                rankChangeText += ` (下降 ${Math.abs(rankChange)} 名)`;
            } else {
                rankChangeText += ` (无变化)`;
            }
            document.getElementById('rankChange').textContent = rankChangeText;
            
            document.getElementById('result').style.display = 'block';
            
            // 滚动到结果区域
            document.getElementById('result').scrollIntoView({ behavior: 'smooth' });
        }

        // 重置表单
        function resetForm() {
            document.getElementById('repSelect').value = '';
            document.getElementById('currentInfo').style.display = 'none';
            document.getElementById('opportunities').innerHTML = '';
            document.getElementById('estimatedSignings').value = '';
            document.getElementById('estimatedAmount').value = '';
            document.getElementById('result').style.display = 'none';
            
            // 移除所有高亮
            const rows = document.querySelectorAll('#repList tbody tr');
            rows.forEach(row => row.classList.remove('highlight'));
            
            // 重新添加一个默认商机表单
            addOpportunity();
        }
    </script>
</body>
</html>